<?php
namespace UserApi\Controller;
use Zend\Mvc\Controller\AbstractRestfulController;
use Zend\View\Model\JsonModel;
class RegistrationApiController extends AbstractRestfulController
{
    public function getList()
    {			
			
    }
    public function get($user_id)
    {		
		header('Access-Control-Allow-Origin: *');
		$data=array();		
		$userTable=$this->getServiceLocator()->get('Models\Model\UserFactory');
		$userData = $userTable->getUserData($user_id)->toarray();
		if(count($userData)!=0){
			return new JsonModel(array(
				'data' => json_encode($userData),
			));
		}else{
			return new JsonModel(array(
				'output' => 'no data',
			));
		}
    }
    public function create($data)
    {
		header('Access-Control-Allow-Origin: *');	
		$userTable=$this->getServiceLocator()->get('Models\Model\UserFactory');
		$userDetailsTable=$this->getServiceLocator()->get('Models\Model\UserDetailsFactory');
		$userRegistration = $userTable->saveUserData($data);
		$userRegistrationDetails = $userDetailsTable->saveUserDetails($data,$userRegistration);
		if($userRegistrationDetails!=0){
			return new JsonModel(array(
				'output' => 'success',
				'User Id'=>	$userRegistration,
			));
		}else{
			return new JsonModel(array(
				'output' => 'not success',
			));
		}
    }
    public function update($uid, $data)
    {
		header('Access-Control-Allow-Origin: *');	
		$userTable=$this->getServiceLocator()->get('Models\Model\UserFactory');
		$userDetailsTable=$this->getServiceLocator()->get('Models\Model\UserDetailsFactory');
		$userRegistration = $userTable->updateUserData($data,$uid);
		$userRegistrationDetails = $userDetailsTable->updateUserDetails($data,$uid);
		if($userRegistrationDetails){
			return new JsonModel(array(
				'output' => 'success',
			));
		}else{
			return new JsonModel(array(
				'output' => 'fail',
			));
		}
    }
    public function delete($id)
    {
       
    }
}